<template>
  <orh-table pages :pageDate="pageDate" >
        <Select v-model="allid" @on-change="formState" style="width:200px" slot="option">
            <Option v-for="item in leavelist" :value="item.value" :key="item.value">{{ item.label }}</Option>
        </Select>
        <Table :columns="columns1" :data="tealeaveLists" slot="table" :loading="tableload"  highlight-row ref="currentRowTable"></Table>
    </orh-table>
</template>

<script>
export default {
    components: {
    },
    name: 'leave-myclassleave',
        data(){
            return {
                allid:'1',
                pageDate: {
                    total: 0,
                    current_page: 1,
                    per_page: 1
                },
                tealeaveLists:[],
                tableload:true,
                url:null,
                leavelist:[
                    {
                        label:'外宿请假',
                        value:'1',
                    },
                    {
                        label:'课堂请假',
                        value:'2',
                    },
                ],
                columns1: [
                   {
                        type: 'selection',
                        width: 60,
                        align: 'center',
                    },
                    {
                        title: '年级',
                        render: (h, params) => {
                            return h('div', params.row.grade!=undefined?params.row.grade.grade_name.zh:'');
                        }
                    },
                    {
                        title: '班级',
                        render: (h, params) => {
                            return h('div', params.row.eclass!=undefined?params.row.eclass.eclass_name.zh:'');
                        }
                    },
                    {
                        title: '学生姓名',
                        render: (h, params) => {
                            return h('div', params.row.student!=null?params.row.student.student_name.zh:'');
                        }
                    },
                    {
                        title: '请假种类',   
                        render: (h, params) => {
                            if(params.row.leave.leave_classifications.dictionary_name!=undefined || params.row.leave.leave_classifications!=undefined){
                                return h('div', params.row.leave.leave_classifications.dictionary_name.zh);
                            }
                        }
                    },
                    {
                        title: '请假开始时间',       
                        align: 'center',
                        key:'start_time',
                    },
                    {
                        title: '请假结束时间',       
                        align: 'center',
                        key:'end_time',
                    },  
                ],             
            }
        },
        
        methods: { 
            /************************************************************
             * 选择类型
             ************************************************************/      
            formState(val){
                if(val!=null){
                    if(val=='1'){
                        this.url = 'api/leave/v1/student_leave/myclass_eclass_leave_index'
                    }else{
                        this.url = 'api/leave/v1/student_leave/myclass_dormitory_leave_index'                               
                    }
                    this.queryData() 
                }
            },     
            /************************************************************
             * 获取数据列表
             ************************************************************/
            queryData(){
                this.tableload = true
                this.$http.get(this.url).then(val=>{
                    this.tealeaveLists = val.data
                    this.pageDate.total=val.pages.total
                    this.pageDate.per_page=val.pages.per_page
                    this.pageDate.current_page=val.pages.current_page
                    this.tableload = false                  
                }).catch(err => {
                    if (err.code && err.code == 422) {
                        this.$Message.error(err.message);
                    }
                    this.tableload = false
                })
            },
        },
        mounted(){
            this.formState(1);
        },
}
</script>
